
package com.siyougame.app.config;

import com.siyougame.app.interceptor.LogInterceptor;
import com.siyougame.app.resolver.AppLoginUserHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


@Configuration
public class AuthorizationConfig implements WebMvcConfigurer {//implements WebMvcConfigurer

    //注入拦截器
    //@Autowired
    //private AccessTokenInterceptor accessTokenInterceptor;
    @Autowired
    private LogInterceptor logInterceptor;
    @Autowired
    private AppLoginUserHandlerMethodArgumentResolver appLoginUserHandlerMethodArgumentResolver;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor).addPathPatterns("/**").excludePathPatterns("/user/login")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {

        resolvers.add(appLoginUserHandlerMethodArgumentResolver);

    }
    //@Bean
    //public OptimisticLockerInterceptor optimisticLockerInterceptor() {
    //    return new OptimisticLockerInterceptor();
    //}

}

